package com.jy.api.domain;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang.StringUtils;

@Data
@XStreamAlias("xml")
@ToString
public class SwiftPassMicroPayBaseResult extends SwiftPassBaseResult {
    @XStreamAlias("result_code")
    private String resultCode;

    @XStreamAlias("mch_id")
    private String mchId;

    @XStreamAlias("device_info")
    private String deviceInfo;

    @XStreamAlias("nonce_str")
    private String nonceStr;

    @XStreamAlias("err_code")
    private String errCode;

    @XStreamAlias("err_msg")
    private String errMsg;

    @XStreamAlias("sign")
    private String sign;

    @XStreamAlias("need_query")
    private String needQuery;

    @XStreamAlias("openid")
    private String openid;

    @XStreamAlias("sub_openid")
    private String subOpenid;

    @XStreamAlias("is_subscribe")
    private String isSubscribe;

    @XStreamAlias("pay_result")
    private String payResult;


    @XStreamAlias("sub_is_subscribe")
    private String subIsSubscribe;

    @XStreamAlias("sub_appid")
    private String subAppid;


    @XStreamAlias("bank_type")
    private String bankType;

    @XStreamAlias("bank_billno")
    private String bankBillno;

    /**
     * status与result code都为0时，支付成功
     *
     * @return 支付是否成功
     */
    @Override
    public boolean isSuccess() {
        if (status.equals("0") && StringUtils.isNotEmpty(resultCode) && resultCode.equals("0")) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean isNeedQuery() {
        if (StringUtils.isEmpty(needQuery) || needQuery.equalsIgnoreCase("Y")) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean isFailed() {
        // status是通信标志，比如中信在缺少必要字段时，会返回410
        if ((StringUtils.isNotEmpty(needQuery) && needQuery.equalsIgnoreCase("N"))) {
            return true;
        } else {
            return false;
        }
    }

}
